import java.io.*;
import java.net.*;
import java.util.*;

public class SingleUDPClient {
  
  public static void main(String[] args) throws IOException {
    if (args.length != 1) {
      System.out.println("Usage: java SingleUDPClient <hostname>");
      return;
    }

    // get a datagram socket
    DatagramSocket socket = new DatagramSocket();

    try {
      // send request
      byte[] buf = new byte[256];
      InetAddress address = InetAddress.getByName("localhost");
      DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4445);
      socket.send(packet);
  
      // get response
      packet = new DatagramPacket(buf, buf.length);
      socket.receive(packet);
  
      // display response
      String received = new String(packet.getData());
      System.out.println("Quote of the Moment: " + received);
    }
    catch (IOException ex) {
      System.out.println(ex);
    }

    socket.close();
  }
}
